﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Framework;
using TjZheng.SSO.Business;
using TjZheng.SSO.DataEntity;
using TjZheng.Cache;

namespace TjZheng.SSO.Process
{
    public partial class UserProcess
    {
        /// <summary>
        /// 用户注销
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual InvokeResult LoginOut(string id)
        {
            InvokeResult objInvokeResult = ConvertUserInfo(id);
            if (objInvokeResult.ResultCode != "Success")
            {
                return objInvokeResult;
            }

            BizTempInfo objBizTempInfo = new BizTempInfo();
            TempInfo objTempInfo = objBizTempInfo.GetRecordCache("", TimeSpan.FromSeconds(5), "ObjectId=@ObjectId AND ObjectCode='UserInfo'", "ObjectId".CreateSqlParameters(id));

            objInvokeResult.ResultMessage = "注销成功";
            if (objTempInfo == null || objTempInfo.EffectiveDate.IsLessThanCurrent())
            {
                return objInvokeResult;
            }
            objTempInfo.EffectiveDate = objTempInfo.EffectiveDate.AddDays(-1);
            objBizTempInfo.Update(objTempInfo);
            return objInvokeResult;
        }
    }
}
